﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.IoTManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.IoTManagement.MeterParameterVMs
{
    public partial class MeterParameterListVM : BasePagedListVM<MeterParameter_View, MeterParameterSearcher>
    {
        
        protected override IEnumerable<IGridColumn<MeterParameter_View>> InitGridHeader()
        {
            return new List<GridColumn<MeterParameter_View>>{
                
                this.MakeGridHeader(x => x.MeterParameter_Device).SetTitle(@Localizer["Page.设备"].Value),
                this.MakeGridHeader(x => x.MeterParameter_ParamName).SetTitle(@Localizer["Page.参数名称"].Value),
                this.MakeGridHeader(x => x.MeterParameter_ParameterAddress).SetTitle(@Localizer["Page.参数地址"].Value),
                this.MakeGridHeader(x => x.MeterParameter_ParameterDataType).SetTitle(@Localizer["Page.数据类型"].Value),
                this.MakeGridHeader(x => x.MeterParameter_ParamUnit).SetTitle(@Localizer["Page.参数单位"].Value),
                this.MakeGridHeader(x => x.MeterParameter_Description).SetTitle(@Localizer["Page.参数说明"].Value),
                this.MakeGridHeader(x => x.MeterParameter_Eanble).SetTitle(@Localizer["Sys.Enable"].Value),
                this.MakeGridHeader(x => x.MeterParameter_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.MeterParameter_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.MeterParameter_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.MeterParameter_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.MeterParameter_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<MeterParameter_View> GetSearchQuery()
        {
            var query = DC.Set<MeterParameter>()
                
                .CheckEqual(Searcher.DeviceId, x=>x.DeviceId)
                .CheckContain(Searcher.ParamName, x=>x.ParamName)
                .CheckContain(Searcher.ParameterAddress, x=>x.ParameterAddress)
                .CheckEqual(Searcher.ParameterDataType, x=>x.ParameterDataType)
                .CheckContain(Searcher.ParamUnit, x=>x.ParamUnit)
                .CheckContain(Searcher.Description, x=>x.Description)
                .CheckEqual(Searcher.Eanble, x=>x.Eanble)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new MeterParameter_View
                {
				    ID = x.ID,
                    
                    MeterParameter_Device = x.Device.DeviceCode,
                    MeterParameter_ParamName = x.ParamName,
                    MeterParameter_ParameterAddress = x.ParameterAddress,
                    MeterParameter_ParameterDataType = x.ParameterDataType,
                    MeterParameter_ParamUnit = x.ParamUnit,
                    MeterParameter_Description = x.Description,
                    MeterParameter_Eanble = x.Eanble,
                    MeterParameter_CreateTime = x.CreateTime,
                    MeterParameter_UpdateTime = x.UpdateTime,
                    MeterParameter_CreateBy = x.CreateBy,
                    MeterParameter_UpdateBy = x.UpdateBy,
                    MeterParameter_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class MeterParameter_View: MeterParameter
    {
        
        public string MeterParameter_Device { get; set; }
        public string MeterParameter_ParamName { get; set; }
        public string MeterParameter_ParameterAddress { get; set; }
        public TagDataTypeEnum? MeterParameter_ParameterDataType { get; set; }
        public string MeterParameter_ParamUnit { get; set; }
        public string MeterParameter_Description { get; set; }
        public bool? MeterParameter_Eanble { get; set; }
        public DateTime? MeterParameter_CreateTime { get; set; }
        public DateTime? MeterParameter_UpdateTime { get; set; }
        public string MeterParameter_CreateBy { get; set; }
        public string MeterParameter_UpdateBy { get; set; }
        public bool MeterParameter_IsValid { get; set; }

    }

}